<%--
  Created by IntelliJ IDEA.
  User: gaosubo
  Date: 2020/10/23
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用餐审核</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css?2019101815.40">
    <link rel="stylesheet" href="/lib/layui/layui/css/treeTable.css?2019101815.17">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/modules/layer/default/layer.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <%--js--%>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/base/base.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <style>
        .layui-form-item {
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <div class="headImg" style="padding-top: 10px">
					<span style="font-size:22px;margin-left:10px;color:#494d59;margin-top: 2px"><img style="margin-left:1.5%" src="../img/commonTheme/theme6/icon_summary.png" alt="">
                        <span style="margin-left: 10px">用餐审核</span>
                    </span>
        </div>
    </div>
    <div class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <input type="radio" lay-filter="college" name="college" value="0" title="待批" checked>
                <input type="radio" lay-filter="college" name="college" value="1" title="已批" >
                <input type="radio" lay-filter="college" name="college" value="2" title="未批" >
            </div>
        </div>
    </div>

    <table id="mealverify" lay-filter="mealverify"></table>
</div>

<%--自定义事件--%>
<script type="text/html" id="doSth">
    {{#  if(d.college == '0' || d.college == '2'){ }}
    <a class="layui-btn layui-btn-xs layui-btn-light"  lay-event="agree">批准</a>
    {{#  } }}

    {{# if(d.college == '0' || d.college == '1') { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="disagree">不批准</a>
    {{# } }}
</script>

<script type="application/javascript">
    layui.use(['table','layer', 'element', 'layedit','form'], function () {
        var table = layui.table,
            layer = layui.layer,
            element = layui.element,
            layedit = layui.layedit,
            form = layui.form;
        form.render();

        table.render({
            elem: '#mealverify',
            url: '/MealManage/getMealMap',
            where: {
                useFlag:true,
                mealType:'1',
                college:'0'
            },
            parseData: function (res) {
                return {
                    "code": 0,
                    "data": res.obj,
                    "count": res.totleNum,
                };
            },
            page: true,
            cols: [[
                {field: 'userName', title: '申请人', align: 'center'}
                , {field: 'deptName', title: '部门', align: 'center'}
                , { title: '审核状态', align: 'center', templet: function (d) {
                        if (d.college == '0') {
                            return "待审批"
                        } else if (d.college == '1') {
                            return "通过"
                        } else if (d.college == '2') {
                            return "未通过"
                        }
                    }},
                {field: 'breakfastNum', title: '早餐（份）', align: 'center'},
                {field: 'lunchNum', title: '中餐（份）', align: 'center'},
                {field: 'predestineTime', title: '预定时间', align: 'center'},
                {field: '', title: '操作', align: 'center', toolbar: '#doSth'}
            ]]
        });

        table.on('tool(mealverify)', function (obj) {
            var event = obj.event;
            var data = obj.data;

            if (event == "agree") {
                layer.confirm('确定批准?', {icon: 3, title:'提示'}, function(index){
                    $.get('/MealManage/editMealMap',{
                        mealId:data.mealId,
                        college:'1'
                    },function(res){
                        if (res.flag){
                            //成功后更新表格
                            table.reload('mealverify');
                        }
                    });
                    layer.close(index);
                });
            }else if (event == "disagree") {
                layer.confirm('确定不批准?', {icon: 3, title:'提示'}, function(index){
                    $.get('/MealManage/editMealMap',{
                        mealId:data.mealId,
                        college:'2'
                    },function(res){
                        if (res.flag){
                            //成功后更新表格
                            table.reload('mealverify');
                        }
                    });

                    layer.close(index);
                });
            }
        })

        //监听单选
        form.on('radio(college)', function(data){
            table.reload('mealverify', {
                where: {
                    college:data.value
                }
            });
        });
    })
</script>
</body>
</html>
